package de.jamm.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;


public class JammDialog extends JDialog implements ActionListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel absolutePane = null;
	private JPanel contentPane = new JPanel();
	private Frame owner = null;
	private String message = null;
	private static JammDialog thisDia = null;
	public JammDialog(Frame owner, String title, String message, JammButton[] btns) {
		super(owner, title);
		super.setUndecorated(true);
		super.setSize(300, 100);
		owner.setEnabled(false);
		
		thisDia = this;
		
		
		
		absolutePane = (JPanel) super.getContentPane();
		AbsolutePanel bg = new AbsolutePanel();
		absolutePane.add(bg);
		absolutePane.setBorder(new LineBorder(Color.BLACK));
		contentPane.setBackground(new Color(0,0,0,0));
		bg.add(contentPane,BorderLayout.CENTER);
		FrameHeader<JammDialog> header = new FrameHeader<JammDialog>(this,"images/atte.png");
		bg.add(header,BorderLayout.NORTH);
		this.owner = owner;
		this.message = message;
		setContent();
		
		JPanel foot = new JPanel();
		foot.setBackground(new Color(0,0,0,0));
		foot.setLayout(new FlowLayout());
		bg.add(foot,BorderLayout.SOUTH);
		
		for(JammButton temp: btns){
			temp.addActionListener(this);
			foot.add(temp);
		}
		
		super.pack();
	}
	public void setCenter(){
		super.setLocation((owner.getX()+owner.getWidth()/2)-this.getWidth()/2,(owner.getY()+owner.getHeight()/2)-this.getHeight()/2);
	}
	@Override
	public void dispose(){
		super.dispose();
		this.getOwner().setEnabled(true);
		this.getOwner().setVisible(true);
		this.getOwner().repaint();
	}
	@Override
	public void actionPerformed(ActionEvent e){
	}
	public void setContent(){
		JLabel lbMsg = new JLabel(message);
		lbMsg.setForeground(Color.WHITE);
		lbMsg.setFont(new Font("Verdana", Font.BOLD, 12));
		contentPane.add(lbMsg,BorderLayout.CENTER);	
	}
	public JPanel getContentPane() {
		return contentPane;
	}
	public void setContentPane(JPanel contentPane) {
		this.contentPane = contentPane;
	}
	public Frame getOwner() {
		return owner;
	}
	public void setOwner(Frame owner) {
		this.owner = owner;
	}
	public static JammDialog getThisDia() {
		return thisDia;
	}
	public static void setThisDia(JammDialog thisDia) {
		JammDialog.thisDia = thisDia;
	}

}
